from django.http import JsonResponse

from dashboard.models import Dashboard
from dvadmin.utils.viewset import CustomModelViewSet
from personal.models import Skill


class DashboardViewSet(CustomModelViewSet):
    """
    """
    queryset = Dashboard.objects.all()
    filter_fields = []
    search_fields = []


def get_radar(request):
    """
    获取雷达数据
    """
    queryset = Skill.objects.all()

    skill_indicators = []  # 技能图表指示器
    skill_datas = []  # 技能分数

    for query in queryset:
        skill_indicators.append({'text': query.name, "max": 100})
        skill_datas.append(query.score)

    data = {
        "title": "个人能力展现",
        "legend": ["编程技能"],
        "indicator": skill_indicators,
        "datas": skill_datas
    }

    return_dict = {
        "msg": "获取成功",
        "data": data
    }

    return JsonResponse(data=return_dict)
